package com.chinasoft.dao;

import com.chinasoft.pojo.Role;

import com.chinasoft.tools.DBUtil;
import org.springframework.stereotype.Repository;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
@Repository
public class RoleDaoImpl implements RoleDao{
    Connection connection;
    @Override
    public List<Role> getRoleList(Connection connection) {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        List<Role> roleList = new ArrayList<>();
        try{
            if(connection != null) {
            String sql = "select * from smbms_role";
            pstm = connection.prepareStatement(sql);
            rs = pstm.executeQuery();
            while (rs.next()) {
                Role role = new Role();
                role.setId(rs.getInt("id"));
                role.setRoleCode(rs.getString("roleCode"));
                role.setRoleName(rs.getString("roleName"));
                roleList.add(role);
                }
            }
        }catch(Exception e){
            e.printStackTrace();
        }
            DBUtil.closeResource(null, pstm, rs);

        return roleList;
    }
}
